package fr.epsi.activities.service;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import com.example.MyLittleHotel.R;
import fr.epsi.BDD.BDD;

import java.sql.SQLException;

/**
 * Created by Florent Baudon on 21/05/2014.
 */
public class ServiceActivity extends ListActivity {

    private BDD bdd;
    private Cursor cListInfo;

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.servicelayout);

        try{
            bdd = new BDD();
            bdd.open(this);
            cListInfo = bdd.getServices();
        }catch (SQLException e){
            e.printStackTrace();
        }
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cListInfo, new String[]{"nom"}, new int[]{android.R.id.text1});
        setListAdapter(adapter);
    }
    protected void onListItemClick (ListView l, View v, int position, long id){
        super.onListItemClick(l, v, position, id);
        TextView tv = (TextView)v;

        Intent i = new Intent(this, EmployesServiceActivity.class);
        i.putExtra("nom", tv.getText().toString());
        startActivity(i);
    }
}